package com.baizhi.wd.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baizhi.wd.entity.User;
import com.baizhi.wd.service.UserService;
import com.baizhi.wd.service.UserServiceImpl;

public class RegistAction extends HttpServlet {
	public void service(HttpServletRequest request,HttpServletResponse response ) throws ServletException, IOException{
		UserService service=null;
		try{
			//1获取表单数据
			String name = request.getParameter("username");
			String pwd = request.getParameter("password");
			User uu = new User(name,pwd);
			//2 调用业务类的查所有方法，检查帐号
			service = new UserServiceImpl();
			List<User> queryall = service.queryall();
			for (User user : queryall) {
				if(!user.getUsername().equals(name)&&!user.getPassword().equals(pwd)){
					service.regist(uu);
					RequestDispatcher rd = request.getRequestDispatcher("/LoginView.html");
					rd.forward(request, response);
					return;
				}
			}
			
		}catch(Exception e){
			e.printStackTrace();
			response.sendRedirect("/telbook_2/RegistView.html");
			/*RequestDispatcher rd = request.getRequestDispatcher("/RegistView.html");
			rd.forward(request, response);*/
			
		}
	}
}
